<template>
    <a-form class="smart-query-form" v-privilege="'oa:enterprise:query'">
      <a-row class="smart-query-form-row">
        <a-form-item label="登录名" class="smart-query-form-item">
          <a-input style="width: 300px" v-model:value="queryForm.username" />
        </a-form-item>
        <a-form-item label="姓名" class="smart-query-form-item">
          <a-input style="width: 300px" v-model:value="queryForm.displayName" />
        </a-form-item>
        <a-form-item label="员工编号" class="smart-query-form-item">
          <a-input style="width: 300px" v-model:value="queryForm.employeeNumber" />
        </a-form-item>
        <a-form-item label="开始时间" class="smart-query-form-item">
          <a-date-picker style="width: 300px" v-model:value="queryForm.startDate" valueFormat="YYYY-MM-DD" />
        </a-form-item>
        <a-form-item label="结束时间" class="smart-query-form-item">
          <a-date-picker style="width: 300px" v-model:value="queryForm.endDate" valueFormat="YYYY-MM-DD" />
        </a-form-item>
  
        <a-form-item class="smart-query-form-item smart-margin-left10">
          <a-button-group>
            <a-button type="primary" @click="onSearch">
              <template #icon>
                <SearchOutlined />
              </template>
              查询
            </a-button>
            <a-button @click="resetQuery">
              <template #icon>
                <ReloadOutlined />
              </template>
              重置
            </a-button>
          </a-button-group>
        </a-form-item>
      </a-row>
    </a-form>
  
    <a-card size="small" :bordered="false" :hoverable="true">
      <a-table size="small" rowKey="id" :dataSource="tableData" :columns="columns" :pagination="false"
        :loading="tableLoading" bordered>
        <template #bodyCell="{ column, record, text, index }">
          <template v-if="column.dataIndex === 'index'">
            {{ index+1 }}
          </template>
        </template>
      </a-table>
  
      <div class="smart-query-table-page">
        <a-pagination showSizeChanger showQuickJumper show-less-items :pageSizeOptions="PAGE_SIZE_OPTIONS"
          :defaultPageSize="queryForm.pageSize" v-model:current="queryForm.pageNumber"
          v-model:pageSize="queryForm.pageSize" :total="total" @change="ajaxQuery" @showSizeChange="ajaxQuery"
          :show-total="(total) => `共${total}条`" />
      </div>
    </a-card>
  </template>
  <script setup>
  import { reactive, ref, onMounted } from 'vue';
  import { PAGE_SIZE, PAGE_SIZE_OPTIONS } from '/@/constants/common-const';
  import { smartSentry } from '/@/lib/smart-sentry';
  import { logAuditApi } from '/@/api/system/logAudit-api'
  
  
  // --------------------------- 企业表格 列 ---------------------------
  const columns = ref([
    {
      title: '序号',
      dataIndex: 'index',
      width: 50,
      align: 'center'
    },
    {
      title: '主题',
      dataIndex: 'topic',
    },
    {
      title: '内容',
      dataIndex: 'message',
      ellipsis: true,
    },
    {
      title: '操作',
      dataIndex: 'messageAction',
    },
    {
      title: '结果',
      dataIndex: 'messageResult',
    },
    {
      title: '操作人',
      dataIndex: 'displayName',
    },
    {
      title: '执行时间',
      dataIndex: 'executeTime',
    }
  ]);
  
  // --------------------------- 查询 ---------------------------
  const queryFormState = {
    pageNumber: 1,
    pageSize: PAGE_SIZE,
    searchCount: true,
    username: '',
    displayName: '',
    employeeNumber: '',
    startDate: '',
    endDate: '',
    // startDatePicker:'',
    // endDatePicker:'',
  };
  const queryForm = reactive({ ...queryFormState });
  const tableLoading = ref(false);
  const tableData = ref([]);
  const total = ref(0);
  
  
  // 查询
  function onSearch() {
    queryForm.pageNumber = 1;
    ajaxQuery();
  }
  // 重置查询
  function resetQuery() {
    Object.assign(queryForm, queryFormState);
    ajaxQuery();
  }
  // 列表数据获取
  async function ajaxQuery() {
    try {
      tableLoading.value = true;
      let responseModel = await logAuditApi.getSystemLogs(queryForm);
      const list = responseModel.data.rows
      total.value = responseModel.data.records;
      tableData.value = list;
    } catch (e) {
      smartSentry.captureError(e);
    } finally {
      tableLoading.value = false;
    }
  }
  onMounted(() => {
    ajaxQuery();
  });
  </script>